package com.ruijiang.result;

import com.github.pagehelper.Page;
import lombok.Builder;
import lombok.Data;


import java.util.List;

@Data
@Builder
public class PageResult {

    //当前页码
    private Integer pageIndex;
    //页面容量
    private Integer pageSize;
    //总页数
    private Integer totalPage;
    //总元素数
    private Long totalCount;
    //页面数据
    private List currentPageRecords;

    //页面构建方法
    public static <T> PageResult pageBuild(Page<T> page) {
        return PageResult.builder()
                .pageIndex(page.getPageNum())
                .pageSize(page.getPageSize())
                .totalCount(page.getTotal())
                .totalPage(page.getPages())
                .currentPageRecords(page.getResult())
                .build();
    }

}
